<?php

# experimental - query class to chain
class EntryQuery extends Doctrine_Query {
	# experimental - automagically retrieve application and set base query for it
	public function __construct(){
		parent::__construct();
		$applicationName=sfConfig::get("sf_app");
        if ($applicationName!=""){
            $methodName="addWhere{$applicationName}";
            if (is_callable(array($this, $methodName))){
                call_user_func(array($this, $methodName));
            }
        }
	}


	public function addWherePublished(){
		return $this->addWhere("published = ?", true);
	}

	public function addWhereSection($section){
		return $this->addWhereSectionId($section->getId());
	}

    public function addWhereSectionId($sectionId){
        return $this->addWhere("section_id = ?", $sectionId);
    }

    public function addWhereSlug($slug){
        return $this->addWhere("id = ?", intval($slug));
    }

	public function addWhereFrontend(){
		return $this;//->addWherePublished(); // entry publishing not done yet
	}
	public function addWhereBackend(){
		return $this;
	}
}